package com.wangjie.define.generic.compare;

public class Sorter {
    public static void sort(Comparable[] arr) {
        for (int i = 0; i < arr.length; i++) {
            /*从第i位开始 筛选出值最小的 引脚*/
            int minPos = i;
            for (int j = i + 1; j < arr.length; j++) {
                minPos = arr[minPos].compare(arr[j]) < 0 ? minPos : j;
            }
            if(minPos > i){
                swap(arr,i,minPos);
            }
        }
    }

    private static void swap(Comparable[] arr, int i, int minPos) {
        Comparable temp = arr[i];
        arr[i] = arr[minPos];
        arr[minPos] = temp;
    }
}
